package com.hr.牛客网剑指offer;

import java.util.ArrayList;
import java.util.Stack;

/**
 * @author zhz
 * @date 2020/08/20
 **/
public class JZ3_从尾到头打印链表 {
    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        ArrayList<Integer> list=new ArrayList<>();
        Stack<ListNode> stack=new Stack();
        ListNode temp=listNode;
        while(temp!=null){
            stack.push(temp);
            temp=temp.next;
        }

        while (!stack.isEmpty()){
            list.add(stack.pop().val);
        }
        return list;
    }
}
